// pages/coupon/coupon.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    coupons:[],
    checkedCouponId:'',
    shopid:"",
    nowCheckId:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const {id} = wx.getStorageSync('checkedJuan');
    if(id){
      console.log("当前id",id);
      this.setData({
        nowCheckId:id
      })
    }
    this.setData({
      shopid:options.shopId
    })
this.getCouPonData()
  },
  radiochange(e){
    this.setData({
      checkedCouponId:e.detail.value
    })
    const {checkedCouponId,coupons} = this.data;
    const obj = coupons.find(n=>n.couponid==checkedCouponId);
    wx.setStorageSync('checkedJuan', obj)
    console.log('radio发生change事件，携带的value值为：',e.detail.value)
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getCouPonData()
  },
  goshopList() {
    wx.switchTab({
      url: "/pages/storeInfo/storeInfo"
    })
  },
  getCouPonData(){
    const userid = wx.getStorageSync('openID');
    wx.request({
      url: 'http://localhost:5555/users/getUserCoupon',
      method:"get",
      data:{
        userid
      },
      success:(res)=>{
        this.setData({
          coupons:res.data
        })
      }
    })
  },
    // 去结算页面
    goToPlaceOrder(e) {
      let id = this.data.shopid
      wx.navigateBack()
    },
})